<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <style type="text/css">

        /* tooltip */
        #tooltip{
            position:absolute;
            border:1px solid #ccc;
            background:#333;
            padding:2px;
            display:none;
            color:#fff;
        }
    </style>
</head>
<body style="padding:10px;">
<div class="tplay-body-div">
    <div class="layui-card-body">
        <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">应用管理</li>
                <li>添加应用</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form serch" action="{:url('admin/app_system/index')}" method="post">
                        <div class="layui-form-item" style="float: left;">
                            <div class="layui-input-inline">
                                <input type="text" name="uid" lay-verify="uid" autocomplete="off" placeholder="请输入ID" class="layui-input layui-btn-sm">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="appname" lay-verify="appname" autocomplete="off" placeholder="请输入应用名" class="layui-input layui-btn-sm">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="appid" lay-verify="appid" autocomplete="off" placeholder="请输入APPID" class="layui-input layui-btn-sm">
                            </div>
                            <div class="layui-input-inline">
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" id="create_time" placeholder="创建时间" name="create_time">
                                    </div>
                                </div>
                            </div>
                            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
                        </div>
                    </form>
                    <table class="layui-table" lay-size="sm">
                        <colgroup>
                            <col width="50">
                            <col width="300">
                            <col width="50">
                            <col width="100">
                            <col width="100">
                            <col width="150">
                            <col width="100">
                            <col width="150">
                            <col width="50">
                            <col width="50">
                            <col width="100">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>应用名</th>
                            <th>缩略图</th>
                            <th>正式版本</th>
                            <th>测试版本</th>
                            <th>发布日期</th>
                            <th>编辑日期</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="shuju" id="vo"}
                        <tr>
                            <td>{$vo.uid}</td>
                            <td>{$vo.appname}</td>
                            <td><a href="{$vo.appico|geturl}" class="tooltip"><img src="{$vo.appico|geturl}" width="20" height="20"></a></td>
                            <td>{$vo.official_version}</td>
                            <td>{$vo.Debug_version}</td>
                            <td>{$vo.create_time}</td>
                            <td>{$vo.update_time}</td>
                            <td class="operation-menu">
                                <div class="layui-btn-group">
                                    <a href="javascript:;" class="layui-btn layui-btn-xs a_menu layui-btn-primary editor" id="{$vo.uid}" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
                                    <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary delete" id="{$vo.uid}" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>
                                    <button class="layui-btn layui-btn-xs layui-btn-primary banben" id="{$vo.uid}">版本管理</button>
                                </div>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                    <div style="padding:0 20px;">{$shuju->render()}</div>
                </div>
                <div class="layui-tab-item">

                    <form class="layui-form" id="admin">

                        <div class="layui-form-item">
                            <label class="layui-form-label">应用名称</label>
                            <div class="layui-input-block" style="max-width:600px;">
                                <input name="appname" lay-verify="appname" autocomplete="off" placeholder="请输入应用名称" class="layui-input" type="text" >
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">APPID</label>
                            <div class="layui-input-block" style="max-width:600px;">
                                <input name="appid" lay-verify="appid" autocomplete="off" placeholder="请输入APPID" class="layui-input" type="text">
                            </div>
                        </div>

                        <div class="layui-upload" id="upload-thumb">
                            <label class="layui-form-label">应用图标</label>
                            <button type="button" class="layui-btn" id="thumb">上传应用图标</button>
                            <div class="layui-upload-list">
                                <label class="layui-form-label"></label>
                                <img class="layui-upload-img" id="demo1" width="150" height="150" >
                                <p id="demoText"></p>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>
<!--    <div class="layui-tab">-->
<!--        <ul class="layui-tab-title">-->
<!--            <li class="layui-this">应用管理</li>-->
<!--            <li><a href="{:url('admin/app_system/publish')}" class="a_menu">新增应用</a></li>-->
<!--        </ul>-->
<!--    </div><button class="layui-btn layui-btn-sm" onclick="add()">添加应用</button>-->

    {include file="public/foot"}
    <script type="text/javascript">

        $('.editor').click(function(){
            var id = $(this).attr('id');
            layer.open({
                type: 2
                ,content: "{:url('admin/app_system/editorapp')}?id=" + id
                ,shadeClose: true
                ,area: ['90%', '90%']
                ,maxmin: true
                ,title:'版本管理'
            });
        })

        $('.delete').click(function(){
            var id = $(this).attr('id');
            layer.confirm('确定要删除?', function(index) {
                $.ajax({
                    url:"{:url('admin/app_system/appdelete')}",
                    data:{id:id},
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.href = res.url;
                            },1500)
                        }
                    }
                })
            })
        })

        $('.banben').click(function(){
            var id = $(this).attr('id');
            layer.open({
                type: 2
                ,content: "{:url('admin/app_system/appVersion')}?id=" + id
                ,shadeClose: true
                ,area: ['90%', '90%']
                ,maxmin: true
                ,title:'版本管理'
            });
        })
    </script>
    <script>
        layui.use('upload', function(){
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#thumb' //绑定元素
                ,url: "{:url('common/upload')}" //上传接口
                ,data:{use:'article_thumb'}
                ,done: function(res){
                    //上传完毕回调
                    if(res.code == 2) {
                        $('#demo1').attr('src',res.src);
                        $('#upload-thumb').append('<input type="hidden" name="appico" value="'+ res.id +'">');
                    } else {
                        layer.msg(res.msg);
                    }
                }
                ,error: function(){
                    //请求异常回调
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });
    </script>
    <script>
        layui.use(['layer', 'form'], function() {
            var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
            $(window).on('load', function() {
                form.on('submit(admin)', function(data) {
                    $.ajax({
                        url:"{:url('admin/app_system/publish')}",
                        data:$('#admin').serialize(),
                        type:'post',
                        async: false,
                        success:function(res) {
                            if(res.code == 1) {
                                layer.alert(res.msg, function(index){
                                    location.href = res.url;
                                })
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                    return false;
                });
            });
        });
    </script>
    <script type="text/javascript">

        $('.is_top').click(function(){
            var val = $(this).attr('data-val');
            var id = $(this).attr('data-id');
            var i = $(this).find('i');
            var the = $(this);
            if(val == 1){
                var is_top = 0;
            } else {
                var is_top = 1;
            }
            $.ajax({
                type:"post",
                url:"{:url('admin/article/is_top')}",
                data:{is_top:is_top,id:id},
                success:function(res){

                    if(res.code == 1) {
                        top();
                    } else {
                        layer.msg(res.msg);
                    }
                }
            })

            function top(){
                if(val == 1){
                    i.attr("class","fa fa-toggle-off");
                    the.attr('data-val',0);
                } else {
                    i.attr("class","fa fa-toggle-on");
                    the.attr('data-val',1);
                }
            }
        })


        $('.status').click(function(){
            var val = $(this).attr('data-val');
            var id = $(this).attr('data-id');
            var i = $(this).find('i');
            var the = $(this);
            if(val == 1){
                var status = 0;
            } else {
                var status = 1;
            }
            $.ajax({
                type:"post",
                url:"{:url('admin/article/status')}",
                data:{status:status,id:id},
                success:function(res){

                    if(res.code == 1) {
                        tostatus();
                    } else {
                        layer.msg(res.msg);
                    }
                }
            })

            function tostatus(){
                if(val == 1){
                    i.attr("class","fa fa-toggle-off");
                    the.attr('data-val',0);
                } else {
                    i.attr("class","fa fa-toggle-on");
                    the.attr('data-val',1);
                }
            }
        })
    </script>
</div>
</body>
</html>
